﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
using LuaFramework;
using System;

public class LwtWindows : EditorWindow{

	List<bool> selectList;
	FileInfo[] files ;
	void Start(){
		

	}

	void OnGUI(){
		GUILayout.Label("csv文件列表", EditorStyles.boldLabel);
		if (GUILayout.Button ("拷贝lua文件")) {
			Packager.CopyHandleLuaFile ();
		}
		//获取指定路径下面的所有资源文件  
		if (files == null) {
			if (Directory.Exists (AppConst.csv_path)) {  
				DirectoryInfo direction = new DirectoryInfo (AppConst.csv_path);  
				files = direction.GetFiles ("*", SearchOption.AllDirectories);  
			}
			selectList = new List<bool> ();
			for (int i = 0; i < files.Length; i++) {
				selectList.Add (false);
			}
		}
		for(int i=0;i<files.Length;i++){  
			if (files[i].Name.EndsWith(".meta")){  
				continue;  
			} 
			selectList [i] = GUILayout.Toggle (selectList [i], files [i].Name);
		}
		if (GUILayout.Button ("打包资源")) {
			btn_clickHandle ();
		}
	}

	void btn_clickHandle(){
		Close ();
		for(int i=0;i<files.Length;i++){
			if (selectList [i]) {
				StreamReader sr = null;
				try{
					sr = File.OpenText(files[i].FullName);
				}catch(Exception e){
					MyDebug.LogRed ("没有找到对应的文件 => "+files[i].FullName);
					return;
				}
				List<string> strList = new List<string> ();
				string line;
				while((line = sr.ReadLine()) != null){
					strList.Add (line);
				}
				sr.Close ();
				sr.Dispose ();
				Packager.HandleBundle (strList,files[i].Name);
			}
		}
		MyDebug.LogRed ("打包完成....");

	}
}
